package cn.yoshii.ad.adserver.chang.ad

import cn.yoshii.ad.adserver.base.RequestUtil
import cn.yoshii.ad.adserver.param.DeviceRequest
import cn.yoshii.libs.jsonutil.toJsonString
import cn.yoshii.libs.okhttputil.OkhttpUtil
import cn.yoshii.libs.webstarter.util.MD5Util

/**
 * @author xiang
 * @Date 2024/2/16 17:44
 **/
object ChangAd {

    private const val TAG = "ChangAd"

    private const val CHANNEL_ID = "oiAEgf"
    private const val CHANNEL_KEY = "14bd27e16751422585781f51f89f3a2a"

    private const val URL = "https://ad.bohaiadx.com/cad/report"

    fun report(
        request: DeviceRequest,
        packId: String,
        requestId: String,
        callbackUrl: String
    ) {
        val time = System.currentTimeMillis()
        val token = MD5Util.md5("$CHANNEL_ID$CHANNEL_KEY$time")
        val report = ChangReportRequest(
            requestId = requestId,
            imei = request.imei,
            oaid = request.oaid,
            packId = packId,
            channelId = CHANNEL_ID,
            time = time,
            token = token,
            callback = callbackUrl
        )
        val resp = OkhttpUtil.postWithJson(URL, json = report.toJsonString())
        RequestUtil.formatResponse<String>(resp, String::class.java)
    }

}